package UsersPackage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/queryUser.do")
public class QueryUserServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        try {
            String username = request.getParameter("username");

            UserDao userService = new UserDao();
            User user = userService.queryUserByUsername(username);
            if (user != null) {
                // Display user information in the response
                System.out.println("dsaasdad");
                response.getWriter().print("User Information:<br>");
                response.getWriter().print("账号: " + user.getUsername() + "<br>");
                response.getWriter().print("用户名: " + user.getUser_id() + "<br>");
                response.getWriter().print("密码: " + user.getPassword() + "<br>");
                // Include other user information as needed
            } else {
                response.getWriter().print("User not found");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Handle POST requests if needed
    }
}
